package review.test2.action;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import review.test2.service.Test2Service;
import review.entity.Test2;

@Controller
@RequestMapping("/test2")
@Api(tags = { "测试数据2操作接口" })
public class Test2Action {
	@Autowired
	private Test2Service test2service;

	@ApiOperation(value = "添加测试数据2", notes = "", httpMethod = "POST")
	@RequestMapping(value = "/add", produces = "application/json;charset=UTF-8")
	@ResponseBody
	public Object add(Test2 param) {
		JSONObject obj = new JSONObject();
		try {
			test2service.addTest2(param);
			obj.put("success", true);
			obj.put("data", param);
		} catch (Exception e) {
			obj.put("message", e.getMessage());
			obj.put("success", false);
		}
		return obj;
	}

	@ApiOperation(value = "删除测试数据2", notes = "", httpMethod = "POST")
	@RequestMapping(value = "/delete", produces = "application/json;charset=UTF-8")
	@ResponseBody
	public Object delect(Integer[] ids) {
		JSONObject obj = new JSONObject();
		try {
			test2service.deleteTest2s(ids);
			obj.put("success", true);
		} catch (Exception e) {
			obj.put("message", e.getMessage());
			obj.put("success", false);
		}
		return obj;
	}

	@ApiOperation(value = "修改测试数据2", notes = "", httpMethod = "POST")
	@RequestMapping(value = "/update", produces = "application/json;charset=UTF-8")
	@ResponseBody
	public Object update(Test2 param) {
		JSONObject obj = new JSONObject();
		try {
			test2service.updateTest2(param);
			obj.put("success", true);
		} catch (Exception e) {
			obj.put("message", e.getMessage());
			obj.put("success", false);
		}
		return obj;
	}

	@ApiOperation(value = "分页查询测试数据2", notes = "", httpMethod = "GET")
	@RequestMapping(value = "/query", produces = "application/json;charset=UTF-8")
	@ResponseBody
	public Object query(Test2 param, @RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "10") int size) {
		JSONObject obj = new JSONObject();
		try {
			Page<Test2> data = test2service.findAll(page, size, param);
			obj.put("success", true);
			obj.put("data", data);
		} catch (Exception e) {
			obj.put("message", e.getMessage());
			obj.put("success", false);
		}
		return obj;
	}

}
